/*	$Id: addr.h 974 2009-08-30 18:46:29Z phrakt $ */
/*
 * Copyright (c) 2009 Jean-Francois Brousseau <phrakt@gmail.com>
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. The name of the author may not be used to endorse or promote products
 *    derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
 * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */


#ifndef _HTTP_ADDR_H_
#define _HTTP_ADDR_H_

#include <sys/types.h>
#include <sys/socket.h>

#include <netinet/in.h>


/*
 * A structure to hold a socket address information.
 *
 *
 */
struct http_sock_addr {
	union {
		struct sockaddr     sa_gen;
		struct sockaddr_in  sa_ipv4;
#if defined(IPV6_SUPPORT)
		struct sockaddr_in6 sa_ipv6;
#endif
	} sa_addr;
};



int          http_addr_getaddr   (const http_sockaddr_t *, void *, size_t);
sa_family_t  http_addr_getfamily (const http_sockaddr_t *);
socklen_t    http_addr_getlen    (const http_sockaddr_t *);
int          http_addr_getport   (const http_sockaddr_t *);
int          http_addr_setaddr   (http_sockaddr_t *, const void *, size_t);
int          http_addr_setfamily (http_sockaddr_t *, sa_family_t);
int          http_addr_setport   (http_sockaddr_t *, int);

const char*  http_addr_ntop      (const http_sockaddr_t *, char *, size_t);
int          http_addr_pton      (const char *, http_sockaddr_t *);


#endif /* _HTTP_ADDR_H_ */
